package com.zlx.guguanjia.Interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author 周罗校
 * @Description  用户登陆拦截
 * @ClassName LoginInterceptor
 * @date 2020.11.03 15:18:37
 * 该版权归周罗校所有，最终解释权以官方为准
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object loginUser = session.getAttribute("loginUser");

        if(loginUser==null){//未登录
//            request.getRequestDispatcher(request.getContextPath()+"/login.html").forward(request,response);
            response.sendRedirect(request.getContextPath()+"/login.html");
            return false;
        }
        return true;
    }

}
